package com.example.demo.mapper;
import com.example.demo.entity.Folder;
import org.apache.ibatis.annotations.*;

@Mapper
public interface FolderMapper {

    @Insert("insert into folder(path,username,be_deleted) values(#{path},#{username},#{beDeleted})")
    Integer insertFolder(Folder folder);

    @Select("select * from folder where path=#{path}")
    Folder selectFolderByPath(String path);

    @Update("update folder set old_path=path,path=concat('${newPath}',SUBSTRING(path, ${len}))where path like '${oldPath}%'")
    Integer updateFolderPath(String oldPath,String newPath,Integer len);


    @Update("update folder set path=old_path,old_path='',be_deleted=0 where path like '${path}%'")
    Integer renewFolderPath(String path);

    @Update("update folder set path=#{newPath} where path=#{oldPath}")
    Integer renameFolderOnePath(String oldPath,String newPath);

    @Update("update folder set path=old_path,old_path='',be_deleted=0 where path=#{path}")
    Integer renewFolderOnePath(String path);

    @Update("update folder set old_path=path,path=#{newPath} ,be_deleted=1 where path=#{oldPath}")
    Integer setFolderPathandDelete(String oldPath,String newPath);

    @Update("update folder set path=concat('${newPath}',SUBSTRING(path, ${len})) where path like '${oldPath}%'")
    Integer updateFileOrFolderPath(String oldPath,String newPath,Integer len);

    @Update("update folder set path=#{newPath} where path=#{oldPath}")
    Integer updateFolderOnlyPath(String oldPath,String newPath);

    @Update("update folder set be_deleted=1 where path like '${path}%'")
    Integer updateFoldersBeDelete(String path);

    @Update("update folder set be_deleted=0 where path like '${path}%'")
    Integer updateFoldersBeDeleteTo0(String path);

    @Delete("delete from folder where path like '${path}%'")
    Integer deleteFolder(String path);

    @Select("select * from folder where path like '${path}%'")
    Folder[] selectFolderByPrepath(String path);

}
